package com.ybfenpan.controller.mall;


public class MathRandom {
	
	 
	/**
	 * Math.random()产生一个double型的随机数，判断一下 例如0出现的概率为%50，则介于0到0.50中间的返回0
	 * 
	 * @return int
	 * 
	 */
	public int PercentageRandom(Double rate0,Double rate1,Double rate2,Double rate3,Double rate4,Double rate5,Double rate6,Double rate7,Double rate8,Double rate9,Double rate10 ) {
		System.out.println("tt:");
		double randomNumber;
		randomNumber = Math.random();
		if (randomNumber >= 0 && randomNumber <= rate0) {
			return 0;
		} else if (randomNumber >= rate0 / 100 && randomNumber <= rate0 + rate1) {
			return 1;
		} else if (randomNumber >= rate0 + rate1 && randomNumber <= rate0 + rate1 + rate2) {
			return 2;
		} else if (randomNumber >= rate0 + rate1 + rate2 && randomNumber <= rate0 + rate1 + rate2 + rate3) {
			return 3;
		} else if (randomNumber >= rate0 + rate1 + rate2 + rate3 && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4) {
			return 4;
		} else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5) {
			return 5;
		} else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 + rate5&& randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+ rate6) {
			return 6;
		} else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+ rate6&& randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+ rate6+ rate7) {
			return 7;
		}else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+ rate6+ rate7&& randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+ rate6+ rate7+ rate8) {
			return 8;
		}else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+ rate6+ rate7+ rate8&& randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+ rate6+ rate7+ rate8+ rate9) {
			return 9;
		}else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+ rate6+ rate7+ rate8+ rate9&& randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+ rate6+ rate7+ rate8+ rate9+ rate10) {
			return 10;
		}
		return -1;
	}

	
}